package com.hexb.smh.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.hexb.smh.entity.enums.ConfigType;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * @author : hexb
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Config implements Serializable {
    private static final long serialVersionUID = -3141425487116842662L;

    private Integer id;

    @ApiModelProperty("配置的类型(目前仅2种类型)")
    private ConfigType type;

    private String value;

    @ApiModelProperty("创建时间")
    @JsonFormat(
            pattern = "yyyy-MM-dd HH:mm:ss",
            timezone = "GMT+8"
    )
    private Date createTime;

    @ApiModelProperty("最后一次修改时间")
    @JsonFormat(
            pattern = "yyyy-MM-dd HH:mm:ss",
            timezone = "GMT+8"
    )
    private Date updateTime;

    @ApiModelProperty("创建人")
    private Integer createBy;

    @ApiModelProperty("最后一次修改人")
    private Integer updateBy;

    @ApiModelProperty("配置值的类型")
    public String getValueType() {
        return type.getType();
    }


    public int intValue() {
        return StringUtils.isEmpty(value) ? 1 : Integer.parseInt(value);
    }
}
